#ifndef F_CPU
#define F_CPU 8000000UL
#endif

#include <avr/io.h>
#include <util/delay.h>

#include "lcd.h"

void lcd_get_chars(char* orig, struct LCD_Chars* dest) {
  
  uint8_t buf_pos = 0;

  while (orig[buf_pos]!='\0') {
    if (buf_pos==0) dest->iii = orig[buf_pos++];
    else if (buf_pos==1) dest->ii = orig[buf_pos++];
    else if (buf_pos==2) dest->i = orig[buf_pos++];
    else if (buf_pos==3) dest->o = orig[buf_pos++];
  }

}


void lcd_write (char higher_to, char high_to, char low_to, char decimal_to, char higher_ld, char high_ld, char low_ld, char decimal_ld)
{
//Setting all LCD ports to output
DDRC |= _BV(DATA7_PIN);
DDRC |= _BV(DATA6_PIN);
DDRC |= _BV(DATA5_PIN);
DDRC |= _BV(DATA4_PIN);
DDRC |= _BV(E_PIN);
DDRC |= _BV(RS_PIN);

//Clearing all the LCD ports
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(E_PIN);
PORTC &= ~_BV(RS_PIN);

//Initializing the LCD

//Setting the LCD to work with 4 data pins 
//upper nibble 0010 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Setting Function (LCD with 2 nibbles and using 2 lines) 
//upper nibble 0010 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1000 and RS 0
PORTC |= _BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Clearing LCD's
//upper nibble 0000 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0001 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing T
//upper nibble 0101 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0100 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing .
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1110 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing o
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1111 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing f
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing f
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing :
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1010 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Spacing
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//WRITING THE NUMBERS OF THE TAKE OFF

//Writing first number (higher_to)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(higher_to & 0x80) PORTC |= _BV(DATA7_PIN);
if(higher_to & 0x40) PORTC |= _BV(DATA6_PIN);
if(higher_to & 0x20) PORTC |= _BV(DATA5_PIN);
if(higher_to & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(higher_to & 0x08) PORTC |= _BV(DATA7_PIN);
if(higher_to & 0x04) PORTC |= _BV(DATA6_PIN);
if(higher_to & 0x02) PORTC |= _BV(DATA5_PIN);
if(higher_to & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing second number (high_to)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(high_to & 0x80) PORTC |= _BV(DATA7_PIN);
if(high_to & 0x40) PORTC |= _BV(DATA6_PIN);
if(high_to & 0x20) PORTC |= _BV(DATA5_PIN);
if(high_to & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(high_to & 0x08) PORTC |= _BV(DATA7_PIN);
if(high_to & 0x04) PORTC |= _BV(DATA6_PIN);
if(high_to & 0x02) PORTC |= _BV(DATA5_PIN);
if(high_to & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing third number (low_to)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(low_to & 0x80) PORTC |= _BV(DATA7_PIN);
if(low_to & 0x40) PORTC |= _BV(DATA6_PIN);
if(low_to & 0x20) PORTC |= _BV(DATA5_PIN);
if(low_to & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(low_to & 0x08) PORTC |= _BV(DATA7_PIN);
if(low_to & 0x04) PORTC |= _BV(DATA6_PIN);
if(low_to & 0x02) PORTC |= _BV(DATA5_PIN);
if(low_to & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing a point (.)
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1110 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing fourth number (decimal_to)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(decimal_to & 0x80) PORTC |= _BV(DATA7_PIN);
if(decimal_to & 0x40) PORTC |= _BV(DATA6_PIN);
if(decimal_to & 0x20) PORTC |= _BV(DATA5_PIN);
if(decimal_to & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(decimal_to & 0x08) PORTC |= _BV(DATA7_PIN);
if(decimal_to & 0x04) PORTC |= _BV(DATA6_PIN);
if(decimal_to & 0x02) PORTC |= _BV(DATA5_PIN);
if(decimal_to & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Spacing
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing f
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing t
//upper nibble 0111 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0100 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Going to the beggining of the second line
//upper nibble 1100 and RS 0
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing L
//upper nibble 0100 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1100 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing a
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0001 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing n
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1110 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing d
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0100 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing :
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1010 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Spacing
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Spacing
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//WRITING THE NUMBERS OF THE LAND

//Writing first number (higher_ld)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(higher_ld & 0x80) PORTC |= _BV(DATA7_PIN);
if(higher_ld & 0x40) PORTC |= _BV(DATA6_PIN);
if(higher_ld & 0x20) PORTC |= _BV(DATA5_PIN);
if(higher_ld & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(higher_ld & 0x08) PORTC |= _BV(DATA7_PIN);
if(higher_ld & 0x04) PORTC |= _BV(DATA6_PIN);
if(higher_ld & 0x02) PORTC |= _BV(DATA5_PIN);
if(higher_ld & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing second number (high_ld)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(high_ld & 0x80) PORTC |= _BV(DATA7_PIN);
if(high_ld & 0x40) PORTC |= _BV(DATA6_PIN);
if(high_ld & 0x20) PORTC |= _BV(DATA5_PIN);
if(high_ld & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(high_ld & 0x08) PORTC |= _BV(DATA7_PIN);
if(high_ld & 0x04) PORTC |= _BV(DATA6_PIN);
if(high_ld & 0x02) PORTC |= _BV(DATA5_PIN);
if(high_ld & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing third number (low_ld)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(low_ld & 0x80) PORTC |= _BV(DATA7_PIN);
if(low_ld & 0x40) PORTC |= _BV(DATA6_PIN);
if(low_ld & 0x20) PORTC |= _BV(DATA5_PIN);
if(low_ld & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(low_ld & 0x08) PORTC |= _BV(DATA7_PIN);
if(low_ld & 0x04) PORTC |= _BV(DATA6_PIN);
if(low_ld & 0x02) PORTC |= _BV(DATA5_PIN);
if(low_ld & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing a point (.)
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1110 and RS 1
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing fourth number (decimal_ld)
//upper nibble 0011 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(decimal_ld & 0x80) PORTC |= _BV(DATA7_PIN);
if(decimal_ld & 0x40) PORTC |= _BV(DATA6_PIN);
if(decimal_ld & 0x20) PORTC |= _BV(DATA5_PIN);
if(decimal_ld & 0x10) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble depends on the variable and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
if(decimal_ld & 0x08) PORTC |= _BV(DATA7_PIN);
if(decimal_ld & 0x04) PORTC |= _BV(DATA6_PIN);
if(decimal_ld & 0x02) PORTC |= _BV(DATA5_PIN);
if(decimal_ld & 0x01) PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Spacing
//upper nibble 0010 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0000 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing f
//upper nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0110 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Writing t
//upper nibble 0111 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 0100 and RS 1
PORTC &= ~_BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC |= _BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Turning the Display ON
//upper nibble 0000 and RS 0
PORTC &= ~_BV(DATA7_PIN);
PORTC &= ~_BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//lower nibble 1100 and RS 0
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC &= ~_BV(DATA5_PIN);
PORTC &= ~_BV(DATA4_PIN);
PORTC &= ~_BV(RS_PIN);

PORTC |= _BV(E_PIN);
_delay_ms(2);
PORTC &= ~_BV(E_PIN);
_delay_ms(2);

//Setting all the data pins high
PORTC |= _BV(DATA7_PIN);
PORTC |= _BV(DATA6_PIN);
PORTC |= _BV(DATA5_PIN);
PORTC |= _BV(DATA4_PIN);

}
